package com.cc.utils;

import com.cc.config.PackagePathConfiguration;
import com.cc.pojo.tablestruct.LibaryProperties;
import com.cc.utils.beanUtil.BeanUtils;


/**
 * @User c.c
 * @Since 2023/4/11
 * @Time 19:47
 * @Description
 */
public class CoreUtil {
  /**
   * @param libaryProperties       数据结构
   * @param isOpenLastDelamination 是否需要最后一层包结构 默认需要 false不需要
   * @param packgePath             包位置
   * @param childPaths             子包名字
   * @return String 路径地址
   * @author C.c
   * @since 2023-04-06 15:56 v1.1
   **/
  public static String getPath(LibaryProperties libaryProperties, StringBuilder packgePath, boolean isOpenLastDelamination, String... childPaths) {
    StringBuilder path = packgePath.append(BeanUtils.getBean(PackagePathConfiguration.class).getPackagePrefix());
    for (String childPath : childPaths) {
      packgePath.append(".").append(childPath);
    }
    if (isOpenLastDelamination) {
      packgePath.append(".").append(ConvertHumpUnderlinesToEachOtherUtil.underlineToHump(libaryProperties.getTableName()));
    }
    return path.toString().replace(".", "\\");
  }

  public static String getPath(LibaryProperties libaryProperties, StringBuilder packgePath, String... childPaths) {
    return getPath(libaryProperties, packgePath, true, childPaths);
  }

}
